package org.zxp.thread.communication.join;

/**
 * @program: zxp-thread-test
 * @description: 测试join
 * join :当我们调用某个线程的这个方法时，这个方法会挂起调用线程，直到被调用线程结束执行，调用线程才会继续执行。
 * @author: X-Pacific zhang
 * @create: 2019-05-18 20:43
 **/
public class JoinTest {
    public static void main(String[] args){
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(3000000000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        },"子线程");
        thread.start();
        //thread插入当前线程（调用join的线程），当前线程挂起，thread运行完毕后当前线程继续
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("运行完毕");
    }
}
